<%@ page import="com.deepai.dprsmgr.utils.ErrCode" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sp" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@include file="../base_path.jsp" %>

<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="description" content="">

    <title>任务详细</title>
	<style type="text/css">
		.direct-chat-hide {
			margin: 0 50px;
			display: none;
			background: #FFF;
			padding: 20px;
		}
		
		.direct-chat-hide input, .direct-chat-hide select, .direct-chat-hide textarea {
			height: 29px;
			border-radius: 5px;
			border: 1px solid #aaa;
			margin-bottom: 5px;
			padding: 0 10px;
			line-height: 28px;
		}
		
		.direct-chat-hide textarea {
			width: 100%;
			overflow: hidden;
		}
		
		.direct-chat-hide-select select {
			width: 100%;
		}
		
		.direct-chat-hide .direct-chat-hide-intention {
			border-radius: 5px;
			border: 1px solid #aaa;
			line-height: 29px;
			color: #3a7fff;
			padding: 0 10px;
			margin-bottom: 5px;
			margin-top: 5px;
		}
		
		.direct-chat-hide-type select {
			margin-right: 15px;
			min-width: 120px;
		}
		
		.direct-chat-status-no {
			color: #007FFF;
		}
		
		.direct-chat-status-amend {
			color: #FF3F00;
		}
		
		.play-rate {
			position: absolute;
			left: 10px;
			height: 30px;
			line-height: 30px;
		}
		
		.play-rate input {
			height: 20px;
			display: inline-block;
			width: 130px;
			position: relative;
			top: 5px;
		}
		.play-rate span {
			display: inline-block;
			line-height: 30px;
		}
		
		.modal-log-title {
			text-align: left;
		}
		
		.modal-dia-header {
			padding: 5px 15px;
			line-height: 30px;
		}
		
		.modal-dia-header .modal-title {
			line-height: 30px;
		}
		
		.modal-dia-header .close {
			margin-top: 2px;
		}
		
		.log-right-btn {
			float: right;
		}
		
		.log1 input[type="radio"] {
			position: relative;
			top: 0px;
		}
		
		.log1 #form_manual_check .control-label {
			float: left;
		}
		
		.log1 #form_manual_check select {
			display: inline-block;
			width: 85px;
		}
		
		.log1 .col-xs-12 {
			margin-bottom: 5px;
		}
		
		.log2 .direct-chat-messages { 
			height: 350px;
		}
		
		.close-info {
			float: right;
			font-size: 21px;
			font-weight: 700;
			line-height: 1;
			color: #FFF;
			text-shadow: 0 1px 0 #fff;
			filter: alpha(opacity=20);
			opacity: 1;
			-webkit-appearance: none;
			padding: 0;
			cursor: pointer;
			background: 0 0;
			border: 0;
			margin-top: 2px;
		}
		
		.log1 .col-xs-12 {
			margin-bottom: 10px;
		}
		
		.log1 .modal-header{
			background: #3247c7;
			border-top-right-radius: 0px;
		}
		
		.log2 .modal-header{
			border-top-left-radius: 0px;
		}
		
		.log2 .modal-header .btn-primary {
			border-color: #FFF;
		}
		
		.log2 input,.log2 textarea ,.log2 select,.log2 .direct-chat-hide-intention{
			background: #eff1f7;
			border: none;
			outline: none;
		}

		.log2.noMark #saveAll{
			display: none;
		}

		.log2.noMark  .direct-chat-status {
			display: none;
		}

		.log2.noMark #exampleModalLabel {
			display: none;
		}
	</style>
</head>
<body>
<!-- 模态框（Modal） -->
<div class="row" style="margin: 0;">
	<div class="col-xs-3 log1" style="padding: 0;">
		<div class="modal-header modal-dia-header">
		   <button type="button" class="close-info"  aria-label="Close"><span aria-hidden="true">&times;</span>
		    </button>
		    <h4 class="modal-title" id="exampleModalLabel">通话详情<span id="dialog_manual_check_status"></span><img style="margin-left: 5px;" src="<%=basePath%>/images/call_dialog_info/check.png" alt="" class="dialog_manual_check_status_check hide"><img style="margin-left: 5px;" src="<%=basePath%>/images/call_dialog_info/checked.png" alt="" class="dialog_manual_check_status_checked hide"></h4>
		</div>
		<div class="modal-body">
			<div class="panel panel-default panel-default-sample">
			    <div class="panel-body">
			        <div class="row">
						<div class="col-xs-12" id="div_business_template">业务模板：</div>
			            <div class="col-xs-12" id="div_call_number">asdasd</div>
			           
			           
			        </div>
					<div class="row hide">
					    <div class="col-xs-12" id="div_task_name">外呼任务：${task.taskName}</div>
					    
					</div>
					<div class="row">
						 <div class="col-xs-12" id="div_answer_time"></div>
						<div class="col-xs-12" id="div_end_time">【结束时间】</div>
						<div class="col-xs-12" id="div_duration_time">【通话时长】</div>
						<div class="col-xs-12 hide" id="div_call_status">【接听状态】</div>
						<div class="col-xs-12" id="div_result"></div>
					</div>
			        
					<div class="row">
					   <!-- <div class="col-xs-12" id="">案例标签：<label><input type="radio" name="a" id="" value="" />优秀案例</label></div>
					    <div class="col-xs-12" style="padding-left: 75px;"><label><input type="radio" name="a" id="" value="" />无效通话</label></div>
						<div class="col-xs-12" style="padding-left: 75px;"><label><input type="radio" name="a" id="" value="" />badcase</label></div> -->
						<div class="col-xs-12" id="" style=""><span style="float: left;">【案例标签】</span><div style="display: inline-block;float: left;">
						<c:forEach var="item" items="${callCaseTypeList}">
							<div style="position: relative;top: -2px">
							<label><input type="radio" name="a" id="" value="${item.typeCode}" class="caseType dpinput" style="margin:0;margin-right: 3px;">${item.typeName}</label>
							</div>
						</c:forEach>
						</div></div>
						
					</div>
					
					<div class="">
						<form class="form-horizontal" id="form_manual_check">
						    <div class="form-group">
								<div class="col-xs-12">
						        <label class="control-label" for="txt_manual_check_comment">备<i style="margin-right: 2em;"></i>注：</label>
									<div class="left">
										<textarea style="width: 173px;" rows="8" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ _,，。.]/g,'')"  id="txt_manual_check_comment" class="form-control input-sm" maxlength="80"
									  placeholder="最多填写80个字..."></textarea>
									</div>
									
								 </div>
								 <div class="col-xs-12 text-c" style="text-align: center;">
								 	<button type="submit" class="btn btn-primary btn-sm submitManual btn-s" value="保存">保存</button>
								 </div>
						    </div>
						</form>
					</div>
			    </div>
			</div>
		</div>
	</div>
	<div class="col-xs-9 log2" style="padding: 0;border-left: 1px solid #ddd;">
		<div class="modal-header modal-dia-header">
		   <button type="button" class="close closeMyModal"  aria-label="Close"><span aria-hidden="true">&times;</span>
		    </button>
			<button class="btn btn-primary btn-sm" id="showLogDetailBtn" style="float: right;margin: 0 10px;">
			   打开/关闭详情
			</button>
			<shiro:hasPermission name="daochuluyin">
			<button class="btn btn-primary btn-sm" id="btn_export_audio" style="float: right;">
			    导出录音
			</button>
			</shiro:hasPermission>
		    <h4 class="modal-title modal-log-title" id="exampleModalLabel">对话测听<span id="span_mark_status"></span>
			<img style="margin-left: 5px;" src="<%=basePath%>/images/call_dialog_info/mark1.png" alt="" class="mark_status1 hide">
			<img style="margin-left: 5px;" src="<%=basePath%>/images/call_dialog_info/mark2.png" alt="" class="mark_status2 hide">
			<img style="margin-left: 5px;" src="<%=basePath%>/images/call_dialog_info/mark3.png" alt="" class="mark_status3 hide">
			</h4>
		</div>
		<div class="modal-body">
		    
		
		    <!--/.direct-chat-messages-->
		    <div class="panel panel-default panel-default-sample" style="margin-bottom: 0px;">
		        <div class="panel-body" style="padding-bottom: 0px;">
		            <div class="row">
		                <div class="progress">
		                    <div class="progress-bar" id="audio_progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
		                        0%
		                    </div>
		                </div>
		            </div>
		            <div class="row">
		                <div id="waveform" style="background-color: #002138; height: 130px"></div>
		            </div>
		            <div class="row" style="margin-top: 5px">
		                <div style="text-align: center;position: relative;padding: 0 10px;">
							<div class="play-rate">
								<span style="margin-right: 10px;">播放速度</span><span>0.5</span><input type="range" name="" id="rate" value="" /> <span>1.5</span>
							</div>
							 <button class="btn btn-primary btn-sm" id="lastAudio" onclick="playLastNextCallInfo(1)">
							    <span class="glyphicon glyphicon-step-backward"></span>&nbsp;
							</button>			
		                    <button class="btn btn-primary btn-sm" id="btnPlayPauseFullAudio" disabled="disabled" style="margin:0 6px;">
		                        <span class="glyphicon glyphicon-play"></span>播放/
		                        <span class="glyphicon glyphicon-pause"></span>暂停
		                    </button>
							 <button class="btn btn-primary btn-sm" id="nextAudio" onclick="playLastNextCallInfo(2)">
							    <span class="glyphicon glyphicon-step-forward"></span>&nbsp;
							</button>
							
							 <button class="btn btn-primary btn-sm" id="saveAll" style="position: absolute; right: 10px;" onclick="saveAllMark()">
							    保存所有标注结果
							</button>			
		                </div>
		            </div>

		            <c:choose>
		                <c:when test="${showAsrResult == true}">
		            <div class="row">
		                </c:when>
		                <c:otherwise>
		            <div class="row hide">
		                </c:otherwise>
		            </c:choose>
		            <div class="box box-primary direct-chat direct-chat-primary" style="margin-top: 5px;margin-bottom: 0px;background: #eff1f7;border-top: none;">
		                <div class="direct-chat-messages" id="dialog_info">
		                    <%--<!-- Message. Default to the left -->--%>
		                    <%--<c:forEach var="item" items="${callDialogueInfoList}">--%>
		                        <%--<c:choose>--%>
		                            <%--<c:when test="${item.channel == 0 && item.content != null && item.content != ''}">--%>
		                                <%--<div class="direct-chat-msg right">--%>
		                                    <%--<div class="direct-chat-info clearfix">--%>
		                                        <%--<span class="direct-chat-name pull-right">用户</span>--%>
		                                        <%--<span class="direct-chat-timestamp pull-left">--%>
		                    <%--<fmt:formatDate value="${item.dialogTime}" pattern="yyyy-MM-dd HH:mm:ss"/></span>--%>
		                                    <%--</div>--%>
		                                    <%--<img class="direct-chat-img" src="<%=basePath%>/images/user.png">--%>
		                                    <%--<div class="direct-chat-text">--%>
		                                            <%--${item.content.replace("<","&lt;").replace(">","&gt;")}--%>
		                                    <%--</div>--%>
		                                <%--</div>--%>
		                            <%--</c:when>--%>
		                            <%--<c:when test="${item.channel == 1 && item.content != null && item.content != ''}">--%>
		                                <%--<div class="direct-chat-msg">--%>
		                                    <%--<div class="direct-chat-info clearfix">--%>
		                                        <%--<span class="direct-chat-name pull-left">机器人</span>--%>
		                                        <%--<span class="direct-chat-timestamp pull-right">--%>
		                    <%--<fmt:formatDate value="${item.dialogTime}" pattern="yyyy-MM-dd HH:mm:ss"/></span>--%>
		                                    <%--</div>--%>
		                                    <%--<!-- /.direct-chat-info -->--%>
		                                    <%--<img class="direct-chat-img" src="<%=basePath%>/images/robot.png">--%>
		                                    <%--<!-- /.direct-chat-img -->--%>
		                                    <%--<div class="direct-chat-text">--%>
		                                            <%--${item.content.replace("<","&lt;").replace(">","&gt;")}--%>
		                                            <%--&lt;%&ndash;<button type="button" class="play_audio_frag btn btn-default btn-xs"&ndash;%&gt;--%>
		                                            <%--&lt;%&ndash;dialogId="${item.id}">&ndash;%&gt;--%>
		                                            <%--&lt;%&ndash;<span class="glyphicon glyphicon-play" aria-hidden="true"></span> 播放&ndash;%&gt;--%>
		                                            <%--&lt;%&ndash;</button>&ndash;%&gt;--%>
		                                    <%--</div>--%>
		                                    <%--<!-- /.direct-chat-text -->--%>
		                                <%--</div>--%>
		                            <%--</c:when>--%>
		                        <%--</c:choose>--%>
		                    <%--</c:forEach>--%>
		
		                    <%--<!-- /.direct-chat-msg -->--%>
		
		                    <%--<!-- Message to the right -->--%>
		
		                    <%--<!-- /.direct-chat-msg -->--%>
		                <%--</div>--%>
		            </div>
		        </div>
		    </div>
		</div>
		        </div>
		    </div>
		    <div class="modal-footer">
		    <button type="button" class="btn btn-default closeMyModal" >关闭</button>
		</div>
		</div>
	</div>
</div>
            



<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var arr_dialog_info, call_info, curRowData;
    var waveSurfer;
	var lastCallId, nextCallId;
	var arr_success_type;
	<%--console.log("+++++++++++++++++++=")--%>
	<%--console.log(${markSwitch})--%>
	var markSwitch = ${markSwitch}
	if(!markSwitch) {
		$(".log2").addClass("noMark");
	}
	
    setTimeout(function () {
		getCallInfo()
        getCallDialogInfoDetail()
        // getDialogCorrectTypeList();
		//$("#span_mark_status").text(call_info.status_name);
		if(call_info.status_name=="未标注") {
			$(".mark_status1").removeClass("hide");
		}else if(call_info.status_name=="已标注") {
			$(".mark_status3").removeClass("hide");
		}else if(call_info.status_name=="部分标注"){
			$(".mark_status2").removeClass("hide");
		}
		
        $(".closeMyModal").click(function(e){

                if (checkContentChange()) {
					bootbox.confirm({
						size: "small",
						message: "内容已修改，您还未保存，是否关闭该页面？",
						buttons: {
		                    confirm: {
		                      label: "关闭"
		                    },
		                    cancel:{
		                        label:"取消"                        
		                    }
	                  	},    
						callback: function(result){
//							console.log(result)
							if(result) {
								 $("#myModal").modal('hide');
							}else {
							}
						}
					})
                    // myNotify("warning", "", "内容已修改请先保存后再关闭页面！", "");
                } else {
//					console.log(3)
                    $('#myModal').modal('hide');
                }

            // if($(this).is(e.target))
        });


        waveSurfer = WaveSurfer.create({
            container: '#waveform',
            splitChannels: true,
            waveColor: '#4bf3a7',
            progressColor: 'white',
            cursorColor: 'white',
            height: 65
//            backend: 'MediaElement'
        });
		
		showDialogInfo()

		/**
         * 保存人工校验结果
         */
        $("#form_manual_check").submit(function (event) {
            var manualCheckComment = $("#txt_manual_check_comment").val().trim();
			var case_type = "";
			var check_success_type_code = $("#select_dialog_manual_check_result_next").val();
			$(".caseType.dpinput").each(function(index, item) {
				if($(item).prop('checked')) {
					case_type = $(item).val();
				}
			})
            event.preventDefault();
            $.ajax({
                url: "<%=basePath%>/call/incoming/saveManualCheckResultInfo.do",
                data: function () {
                    return "call_id=" + call_id + "&manual_check_comment=" + manualCheckComment
						+ "&case_type=" + case_type + "&check_success_type_code=" + check_success_type_code;
                }(),
				type: "post",
                async: false,
                dataType: "json",
                success: function (data) {
                    if (data["errorCode"] == "0") {
//                         var manualResultHtml = getCallManualCheckResultContentByKey(manualCheckResult);
//                         $($table).jqGrid('setRowData', call_id, {manual_check_result: manualResultHtml});
						if($table) {
							refreshJQGrid();
						}
                        myNotify("success", "", "保存成功！", "");
						getCallInfo()
//                        $("#modal_call_dialogue_info").modal('hide');
                    } else {
                        myNotify("error", "", "保存失败！", "");
                    }
                },
                error: function () {
                }
            });
        });
		
		$('#rate').change(function() {
			var rate = $(this).val()/100+0.5;
//			console.log(rate)
			waveSurfer.setPlaybackRate(rate)
		})
		
		$('#showLogDetailBtn').click(function() {
//			console.log($(".log1").is(":hidden"));//是否隐藏)
			var hidden = $(".log1").is(":hidden"); 
			if(hidden) {
				$(".log1").show();
				$(".log2").removeClass("col-xs-12").addClass("col-xs-9");
			}else {
				$(".log1").hide();
				$(".log2").removeClass("col-xs-9").addClass("col-xs-12")
			}
		})
		
		$('.close-info').click(function() {
			$('#showLogDetailBtn').click();
		})
		
		$('.caseType').click(function(){
             
                var domName = $(this).attr('name');

                var $radio = $(this);
                // if this was previously checked
                if ($radio.data('waschecked') == true){
                    $radio.prop('checked', false);
                    $("input:radio[name='" + domName + "']").data('waschecked',false);
                    //$radio.data('waschecked', false);
                } else {
                    $radio.prop('checked', true);
                    $("input:radio[name='" + domName + "']").data('waschecked',false);
                    $radio.data('waschecked', true);
                }
		});

		$("#btn_export_audio").click(function() {
            $.ajax({
                url: '<%=basePath%>/dialog/checkExportSingleAudioData.do',
                data: 'call_id=' + call_id,
                async: false,
                dataType: 'json',
                success: function (data) {
                    if (data["errorCode"] == "0") {
                        window.location.href = "<%=basePath%>/dialog/exportSingleAudioData.do?call_id=" + call_id;
                    } else {
                        myNotify("error", "", "无法导出语音数据！", "");
                    }
                },
                error: function (data) {
                    myNotify("error", "", "操作过程中发生错误，请联系管理员！", "");
                }
            });


		});

		$(document).on("click", ".direct-chat-status", function() {
			$(this).closest(".direct-chat-msg").find(".direct-chat-text").click();
		})
		
		$("#btnPlayPauseFullAudio").click(function() {
			waveSurfer.playPause();
		})
    }, 200);
	
	function saveAllMark() {
		 $.ajax({
		    url: "<%=basePath%>/dialog/markAll.do?call_id="+call_id,
		    data: "",
		    async: false,
		    dataType: "json",
		    success: function (data) {
		      if (data["errorCode"] == "0") {
		         myNotify("success", "", "保存成功！", "");
		      } else {
		         myNotify("error", "", "保存失败！", "");
		      }
		    },
		    error: function (data) {
		
		    }
		});
	}

	function typeCodeChange(obj) {
		getDialogCorrectTypeList($(obj).closest('.direct-chat-msg'))
		setReadOnly(obj)
	}
	
	function setReadOnly(obj) {
		if($(obj).val() == "1000") {
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option[text='请选择']").remove();
			var intention = $(obj).closest('.direct-chat-msg').find(".direct-chat-hide-intention").attr("intention");
			var newOption = '<option text="正确" selected="selected">正确</option>';
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").prepend(newOption)
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-fact textarea").attr("disabled", "disabled").val("")
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option").removeAttr("selected")
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option").prop("disabled",false)
			// $(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option[text='"+intention+"']").prop("selected",true);
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select select").attr("disabled", "disabled")			
		}else {
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option[text='成功']").remove();
			
			var intention = $(obj).closest('.direct-chat-msg').find(".direct-chat-hide-intention").attr("intention");
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-fact textarea").removeAttr("disabled")
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select select").removeAttr("disabled")
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option").removeAttr("selected").removeAttr("disabled")
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option").prop("disabled",false)
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option[text='"+intention+"']").prop("disabled","disabled");
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").find("option[text!='"+intention+"']").eq(0).prop("selected",true);
			var newOption = '<option text="请选择" selected="selected" disabled>请选择正确的意图</option>';
			$(obj).closest('.direct-chat-msg').find(".direct-chat-hide-select").find("select").prepend(newOption)
		}
	}
	
	function getNextManual() {
		// var val = $("#select_dialog_manual_check_result").val();
		 $.ajax({
		    url: "<%=basePath%>/call/getManualCheckSuccessTypeList.do",
		    data: "",
		    async: false,
		    dataType: "json",
		    success: function (data) {
		       var html ='<option value="0"></option>'
		       if (data["errorCode"] == "0") {
//				   console.log(data)
				   $(data.list).each(function(index, item) {
					   html += '<option value="'+item.successTypeCode+'">'+item.successTypeName+'</option>'
				   })
				   $('#select_dialog_manual_check_result_next').html(html)
		       }
		    },
		    error: function (data) {
		
		    }
		});
	}

	function userTextClick(obj) {
		if(!markSwitch) {
			return
		}
//		console.log($(obj).closest('.direct-chat-msg').find('.direct-chat-hide').is(':hidden'))
		if($(obj).closest('.direct-chat-msg').find('.direct-chat-hide').is(':hidden')) {
			// getDialogCorrectTypeList($(obj).closest(".direct-chat-msg").attr("logid"))
			var id = $(obj).closest(".direct-chat-msg").attr("nodeid");
			var logid = $(obj).closest(".direct-chat-msg").attr("logid");
			var manualMark = $(obj).closest(".direct-chat-msg").find(".direct-chat-hide-intention").attr("manualMark")
			getManualMarkList(id,logid);
			$(".direct-chat-msg[nodeid="+logid+"]").find(".direct-chat-hide-select").find("option[text='"+manualMark+"']").attr("selected",true);
		}
		
		$(obj).closest('.direct-chat-msg').find('.direct-chat-hide').slideToggle(300);
	}
	
	function diaSubmitClick(obj) {
		var target = $(obj).closest('.direct-chat-msg');
		var dialog_id = target.attr('logid');
		var correct_type_code = target.find('.direct-correct-list').val();
		var correct_type_content = target.find('.direct-chat-hide-fact textarea').val();
		var nodeContent = target.find('.direct-chat-hide-select select').find("option:selected").text();
		var comment = target.find('.direct-chat-hide-note textarea').val();
		var parent_id = target.find('.direct-typecode').val();
		
		var data = {
			call_id: call_id,
			dialog_id: dialog_id,
			correct_menu_level_one_code: parent_id,
			correct_menu_level_second_code: correct_type_code,
			correct_asr_content: correct_type_content,
			node_content: nodeContent,
			comment: comment,
		}
		
		if(nodeContent == "请选择正确的意图") {
			myNotify("error", "", "请选择正确的意图！", "");
			return
		}
		
		$.ajax({
		    url: "<%=basePath%>/dialog/saveDialogCorrectInfo.do",
		    data: data,
			type: "POST",
		    async: false,
		    dataType: "json",
		    success: function (data) {
				 if (data["errorCode"] == "0") {
				    myNotify("success", "", "保存成功！", "");
				 } else {
				    myNotify("error", "", "保存失败！", "");
				 }
		    },
		    error: function (data) {
		
		    }
		});
//		console.log(data)
	}
	
	function noteTextareaKeyup(obj) {
		$(obj).height(obj.scrollHeight);
	}

    function showDialogInfo() {
        waveSurfer.on("ready", function () {
            $("#audio_progress").attr("aria-valuenow", 100);
            $("#audio_progress").css("width",  '100%');
            $("#audio_progress").text('100%');
            $("#btnPlayPauseFullAudio").removeAttr('disabled');
            waveSurfer.play();
        });
        waveSurfer.on('loading', function (progress) {
//            console.log(progress);
            $("#audio_progress").attr("aria-valuenow", progress);
            $("#audio_progress").css("width", progress + '%');
            $("#audio_progress").text(progress + '%');
        });
		waveSurfer.on("finish",function() {
			
		});
        waveSurfer.load("<%=basePath%>/call/playAudioFull.do?callId=" + call_id);
		if(call_info.answer_time) {
			$("#div_answer_time").text("【接听时间】" + call_info.answer_time);
		}else {
			$("#div_answer_time").text("【接听时间】");
		}
		
		if(call_info.manual_check_status == 1) {
			$(".dialog_manual_check_status_check").removeClass("hide");
		}else if(call_info.manual_check_status == 2) {
			$(".dialog_manual_check_status_checked").removeClass("hide");
		}
		$("#div_business_template").text("【业务名称】" + call_info.business_name);
		// $("#div_task_name").text("【外呼任务】" + call_info.task_name);
        $("#div_call_number").html("【来电号码】" + call_info.phone_number);
        $("#div_result").html("【通话结果】" + call_info.result);
		if(call_info.manual_check_result==1) {
			getNextManual()
			$("#select_dialog_manual_check_result_next").val(call_info.manual_check_result_type)
		}else {
			$("#select_dialog_manual_check_result_next").addClass("hide");
		}
		// $("#select_dialog_manual_check_result_next").val(call_info.manual_check_status);
        $("#txt_manual_check_comment").val(call_info.manual_check_comment);
		$("input:radio[value='" + call_info.case_type + "']").prop('checked', true);
		$("#div_call_status").html("【接听状态】" + call_info.answer_status);
		var end_time = call_info.end_time? call_info.end_time: "";
        $("#div_end_time").html("【结束时间】" + end_time);
        $("#div_duration_time").html("【通话时长】" + secondFormat(call_info.duration));

		if(call_info.case_type) {
			$(".caseType[value='"+call_info.case_type+"']").prop("checked", true);
		}
        $("#dialog_info").empty();
        for (var i = 0; i < arr_dialog_info.length; ++i) {
			var content = "";
            var dialogInfo = arr_dialog_info[i];
//            console.log(dialogInfo)
            if (dialogInfo.channel == 0) {
                var statusHtml;
				if(!markSwitch) {
					statusHtml = ""
				}else {
					statusHtml = getDialogMarkStatusHtmlContent(dialogInfo.dialogUserMarkInfo.dialogMarkStatus);
				}
				if(dialogInfo.dialogUserMarkInfo.diaRound == 1) {
					statusHtml = ""
				}
                var intentionHtml = dialogInfo.robot_intention;
                var manual_mark = dialogInfo.manual_mark;
                var comment = dialogInfo.comment;
				var correct_asr_content = dialogInfo.correct_asr_content;

//				var statusHtml = "<span class='direct-chat-status direct-chat-status-ok'>已标</span>";
				// var statusHtml = "<span class='direct-chat-status direct-chat-status-amend '>已纠</span>"
				// var statusHtml = "<span class='direct-chat-status direct-chat-status-no'>纠错</span>"
				var firstSelect=""
				<c:forEach var="item" items="${dialogMarkCorrectTypeList}">
					firstSelect += '<option value="${item.typeCode}">${item.typeName}</option>'
				</c:forEach>
				var hideDiv = "<div class='direct-chat-hide'>"+
								"<div class='direct-chat-hide-intention' intention='"+ dialogInfo.dialogUserMarkInfo.robotIntention+"' manualMark='"+ dialogInfo.dialogUserMarkInfo.manualMark+"'>意图：" + dialogInfo.dialogUserMarkInfo.robotIntention + "</div>"+
								"<div class='direct-chat-hide-type'>本轮问题类别：<select class='direct-typecode' onchange='typeCodeChange(this)'>"+firstSelect+"</select><select class='direct-correct-list'></select></div>"+
								"<div class='direct-chat-hide-fact'><textarea onkeyup='noteTextareaKeyup(this)' class='noteTextarea' rows='1' placeholder='请输入正确的结果' value='"+dialogInfo.dialogUserMarkInfo.correctAsrContent+"'></textarea></div>"+
								"<div class='direct-chat-hide-select'><select></select></div>"+
								"<div class='direct-chat-hide-note'><textarea class='noteTextarea' onkeyup='noteTextareaKeyup(this)' rows='1' placeholder='请输入备注信息' value='"+dialogInfo.dialogUserMarkInfo.comment+"'></textarea></div>"+
								'<button type="button" class="btn btn-primary btn-sm dia-submit" value="保存" onclick="diaSubmitClick(this)">保存</button>'+
							  "</div>"
				if(dialogInfo.dialogUserMarkInfo.diaRound == 1) {
					hideDiv = ""
				}
                content += "<div class='direct-chat-msg right' logid='"+dialogInfo.id+"' nodeid='"+dialogInfo.dialogUserMarkInfo.flowNode+"'>" +
                    "<div class='direct-chat-info clearfix'>" +
                    "<span class='direct-chat-name pull-right'>用户</span>" +
                    "<span class='direct-chat-timestamp pull-left'>" + dateFormat(dialogInfo.dialogTime) + "</span></div>"+statusHtml+
                    "<img class='direct-chat-img' src='<%=basePath%>/images/user.png'><div class='direct-chat-text user-text' onclick='userTextClick(this)'>"+dialogInfo.content.replace("<","&lt;").replace(">","&gt;")  + "</div>"+hideDiv+"</div>";
                    //replace("<","&lt;").replace(">","&gt;")
            } else if (dialogInfo.channel == 1){
                content += "<div class='direct-chat-msg left' logid='"+dialogInfo.id+"'>" +
                    "<div class='direct-chat-info clearfix'>" +
                    "<span class='direct-chat-name pull-left'>机器人</span>" +
                    "<span class='direct-chat-timestamp pull-right'>" + dateFormat(dialogInfo.dialogTime) + "</span></div>"+
                    "<img class='direct-chat-img' src='<%=basePath%>/images/robot.png'><div class='direct-chat-text'>"+
                    dialogInfo.content.replace("<","&lt;").replace(">","&gt;")   + "</div></div>";
            }
			$("#dialog_info").append(content);
			if (dialogInfo.channel == 0) {
//				console.log(dialogInfo)
//				console.log(dialogInfo.dialogUserMarkInfo.robotIntention)
//				console.log(dialogInfo.id)
				<!-- getDialogCorrectTypeList($(".direct-chat-msg[logid="+dialogInfo.id+"]")) -->
				$(".direct-chat-msg[logid="+dialogInfo.id+"]").find(".direct-chat-hide-select").find("select").find("option").removeAttr("selected");
				$(".direct-chat-msg[logid="+dialogInfo.id+"]").find(".direct-chat-hide-fact textarea").val(dialogInfo.dialogUserMarkInfo.correctAsrContent);
																							   
				$(".direct-chat-msg[logid="+dialogInfo.id+"]").find(".direct-chat-hide-select").find("option[text='"+dialogInfo.dialogUserMarkInfo.robotIntention+"']").attr("selected",true);
				$(".direct-chat-msg[logid="+dialogInfo.id+"]").find(".direct-chat-hide-note textarea").val(dialogInfo.dialogUserMarkInfo.comment)
				if(dialogInfo.dialogUserMarkInfo.correctMenuLevelOneCode){
					var v1 = dialogInfo.dialogUserMarkInfo.correctMenuLevelOneCode
					$(".direct-chat-msg[logid="+dialogInfo.id+"]").find('.direct-typecode').val(v1);
					getDialogCorrectTypeList($(".direct-chat-msg[logid="+dialogInfo.id+"]"))
					var v2 = dialogInfo.dialogUserMarkInfo.correctMenuLevelSecondCode
					$(".direct-chat-msg[logid="+dialogInfo.id+"]").find('.direct-correct-list').val(v2)					
				}
				setReadOnly($(".direct-chat-msg[logid="+dialogInfo.id+"]").find(".direct-typecode"))
			}
        }
        //$("#dialog_info").html(content);

    }
	
	function checkContentChange() {
	    var mcComment = $("#txt_manual_check_comment").val().trim();
	    return  (call_info.manual_check_comment != null && call_info.manual_check_comment != mcComment)
	        || (call_info.manual_check_comment == null && mcComment != "");
	}
	
	
	function getCallInfo() {//获取通话信息
		$.ajax({
		    url: "<%=basePath%>/call/getCallInfoForDialog.do",
		    data: "call_id=" + call_id,
		    async: false,
		    dataType: "json",
		    success: function (data) {
//				console.log(data)
				call_info = data.map;
		    },
		    error: function (data) {
		
		    }
		});
	}
	
	function getCallDialogInfoDetail() {//获取通话文本内容
	    $.ajax({
	        url: "<%=basePath%>/call/getCallDialogueInfo.do",
	        data: "callId=" + call_id,
	        async: false,
	        dataType: "json",
	        success: function (data) {
//				console.log(data)
	            if (data["errorCode"] == "0") {
	                arr_dialog_info = data["callDialogueInfoList"];
	            }
	        },
	        error: function (data) {
	
	        }
	    });
		getLastNextCallId(call_id)
	}


	
	//获取上一条或下一条id
	function getLastNextCallId(id) {
		var data = getJQGridFilterData();
		data.callId = id;
		//curRowData = jQuery("#callInfoJQGrid").jqGrid('getRowData', callId);
		$.ajax({
		    url: "<%=basePath%>/call/getLastNextCallId.do",
		    data: data,
		    async: false,
		    dataType: "json",
			type: "post",
		    success: function (data) {
//				console.log(data)
		        if (data["errorCode"] == "0") {
					lastCallId = data.map.lastCallId;
					nextCallId = data.map.nextCallId;
					$('#lastAudio').prop('disabled', false);
					$('#nextAudio').prop('disabled', false);
					if(!lastCallId) {
						$('#lastAudio').prop('disabled', true);
					}
					
					if(!nextCallId) {
						$('#nextAudio').prop('disabled', true);
					}
		        }
		    },
		    error: function (data) {
		
		    }
		});
	}
	
   //播放上一条或下一条信息  index: 1播放上一条 2播放下一条
   function playLastNextCallInfo(index) {
   	if (checkContentChange()) {
   	    myNotify("warning", "", "内容已修改，请先保存再进行操作", "");
   		return false
   	}
   	 destroyWave()
	 call_id = lastCallId;
	 if(index==2) {
		 call_id = nextCallId;
	 }
//	 console.log('*****'+call_id)
//    	 var targetCallId = lastCallId;
//    	 if(index==2) {
//    		 targetCallId = nextCallId;
//    	 }
//    	 $.ajax({
//    	    url: "<%=basePath%>/call/getCallDialogueInfo.do",
//    	    data: "callId=" + targetCallId,
//    	    async: true,
//    	    dataType: "json",
//    	    success: function (data) {
//    			console.log(data)
//    	        if (data["errorCode"] == "0") {
// //    	           curRowData = {
// //    	           	answer_time :dateFormat(data["callInfo"].answerTime),
// //    	           	phone_number: data["callInfo"].phoneInfo.phoneNumber
// //    	           }
//    	           call_info = data["callInfo"];
//    	           arr_dialog_info = data["callDialogueInfoList"];
//    	           showDialogInfo();
//    	        }
//    	    },
//    	    error: function (data) {
//
//    	    }
//    	});
	getCallInfo()
	getCallDialogInfoDetail()
	showDialogInfo()
   	getLastNextCallId(call_id)
   }

    function getDialogCorrectTypeList(form) {
        $.ajax({
            url: "<%=basePath%>/call/getDialogCorrectTypeList.do",
            data: "parent_id=" + form.find('.direct-typecode').val(),
            async: false,
            dataType: "json",
            success: function (data) {
               var html =""
               if (data["errorCode"] == "0") {
//				   console.log(data)
				   $(data.list).each(function(index, item) {
					   html += '<option value="'+item.typeCode+'">'+item.typeName+'</option>'
				   })
				   form.find('.direct-correct-list').html(html)
               }
            },
            error: function (data) {

            }
        });
    }
	
	function getManualMarkList(id,logid) {
		$.ajax({
		    url: "<%=basePath%>/business/getManualMarkList.do",
		    // data: "call_id="+call_id+"&node_id="+id,
			data: {
				call_id: call_id,
				node_id: id
			},
			type: "post",
		    async: false,
		    dataType: "json",
		    success: function (data) {
		         if (data["errorCode"] == "0") {
//		        	console.log(data)
					var html =""
					var intention = $('.direct-chat-msg[nodeid='+id+']').find('.direct-chat-hide-intention').attr("intention");
		        	$(data.list).each(function(index, item) {
						if(intention == item) {
							html += '<option text="'+item+'" selected>'+item+'</option>'
						}else {
							html += '<option text="'+item+'">'+item+'</option>'
						}
		        		
		        	 })
		        	$('.direct-chat-msg[nodeid='+id+']').find('.direct-chat-hide-select select').html(html)
					setReadOnly($('.direct-chat-msg[logid='+logid+']').find(".direct-typecode"))
		        }
		    },
		    error: function (data) {
		
		    }
		});
	}

    function getManualCheckSuccessType() {
        $.ajax({
            url: "<%=basePath%>/call/getManualCheckSuccessTypeList.do",
            data: "parent_id=" + parent_id,
            async: false,
            dataType: "json",
            success: function (data) {
//                console.log(data)
                if (data["errorCode"] == "0") {
                    arr_success_type = data["list"];
                }
            },
            error: function (data) {

            }
        });
    }
    function getUrlParms(name) {
    	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    	var r = window.location.search.substr(1).match(reg);
    	if (r != null)
    		return unescape(r[2]);
    	return null;
    }

	
    function getCallManualCheckResultContentByKey(code) {
        <c:forEach var="item" items="${manualCheckResultList}">
        var resultCode = "${item.resultCode}";
        if (resultCode == code) {
            return "${item.htmlContent}";
        }
        </c:forEach>
    }

    // 通过标注状态码获取对话中某一轮的标注状态
    function getDialogMarkStatusHtmlContent(code) {
        <c:forEach var="item" items="${dialogMarkStatusList}">
        var status_code = "${item.statusCode}";
        if (status_code == code) {
			
            return "${item.htmlContent}";
        }
        </c:forEach>
    }


    function getCallStatusHtmlContent(code) {
        var statusHtml = "";
        if (code == 1) {
            statusHtml = "<span class='label label-info'>待呼叫</span>";
        } else if (code == 2) {
            statusHtml = "<span class='label label-success'>呼叫中</span>";
        } else if (code == 3) {
            statusHtml = "<span class='label label-primary'>已完成</span>";
        } else if (code == 4) {
            statusHtml = "<span class='label label-warning'>已暂停</span>";
        } else if (code == 5) {
            statusHtml = "<span class='label label-danger'>已终止</span>";
        } else if (code == 6) {
            statusHtml = "<span class='label label-danger'>超时</span>";
        } else if (code == 7) {
            statusHtml = "<span class='label label-default'>黑名单</span>";
        }
        return statusHtml;
    }
	
	function destroyWave() {
		 $("#audio_progress").attr("aria-valuenow", 0);
		$("#audio_progress").css("width", '0%');
		$("#audio_progress").text('0%');
		$("#btnPlayPauseFullAudio").attr('disabled', true);
		waveSurfer.stop();
		waveSurfer.un('ready');
		waveSurfer.un('loading');
		$(this).removeData('bs.modal');
	}
</script>
</body>
</html>
